package com.liziba.demo.slice;

import com.liziba.demo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        //1. 找到组件
        Button button = (Button) this.findComponentById(ResourceTable.Id_button);

        //2. 绑定单击事件
        button.setClickedListener(this::onClick);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }



    public void onClick(Component component) {
        // 具体点击操作的逻辑处理
        Button button = (Button) component;
        button.setText("哦，我被点击了！");
    }
}

/**
 * 实现ClickedListener接口并重写onClick方法
 */
//class ClickedListener implements Component.ClickedListener {
//
//    /**
//     * 点击事件触发的操作会调用的方法
//     * @param component     被点击的组件对象
//     */
//    @Override
//    public void onClick(Component component) {
//        // 具体点击操作的逻辑处理
//        Button button = (Button) component;
//        button.setText("哦，我被点击了！");
//    }
//}